package com.Cheng.controller;


import com.Cheng.pojo.Income;

import com.Cheng.service.IncomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @Author Cheng
 * @Date 2022/4/10 16:40
 */
@Controller
@RequestMapping("/income")
public class IncomeController {
    @Autowired
    @Qualifier("IncomeServiceImpl")
    private IncomeService incomeService;

    @RequestMapping("/allIncome")
    public String list(Model model){
        List<Income> list = incomeService.queryAllIncome();
        model.addAttribute("list", list);
        return "allIncome";
    }
    @RequestMapping("/allIncome1")
    public String list1(Model model){
        List<Income> list = incomeService.queryAllIncome();
        model.addAttribute("list", list);
        return "two3";
    }


    @RequestMapping("/toAddIncome")
    public String toAddPaper() {
        return "addIncome";
    }

    @RequestMapping("/addIncome")
    public String addPaper(Income income) {
        System.out.println(income);
        incomeService.addIncome(income);
        return "redirect:/income/allIncome";
    }

    @RequestMapping("/toUpdateIncome")
    public String toUpdateIncome(Model model, int id) {
        Income income = incomeService.queryIncomeById(id);
        model.addAttribute("income",income );
        return "updateIncome";
    }

    @RequestMapping("/updateIncome")
    public String updateIncome(Model model, Income income) {
        incomeService.updateIncome(income);
        Income income1 = incomeService.queryIncomeById(income.getIncomeID());
        model.addAttribute("income", income1);
        return "redirect:/income/allIncome";
    }

    @RequestMapping("/del")
    public String deleteIncome(int id){
        incomeService.deleteIncomeById(id);
        return "redirect:/income/allIncome";
    }
}
